<% /* $Id: monitor_ioi.jsp 101 2010-12-26 21:25:55Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>


<%
	MonitorInterface monitor = new BasicMonitor(contest.getId());
	monitor.sortIOI();
	
	List<ContestUserEntry> users = monitor.getUsers();
	List<ContestProblemEntry> problems = monitor.getProblems();
%>


<h2>Standings [<%= contest.getContestTimeString() %>]</h2>
<!--  <p>Last success: 632:54:07, UzhNU, D6.</p> -->

<table width="100%" class="standings">
	<tr>
		<th class="st_place">Place</th>
		<th class="st_team">Team</th>
<%
	for (ContestProblemEntry problemEntry: problems)
	{
%>
		<th class="st_prob"><%= problemEntry.getSid() %></th>
<%		
	}
%>
		<th class="st_total">Total score</th>
		<th class="st_pen">Full problems</th>
	</tr>


<%
	int c = 0, last_score = -1, last_place = 0;
	long last_time = -1;
	for (ContestUserEntry userEntry: users)
	{
		ContestUserScoreEntry userScoreEntry = monitor.getUserScore(userEntry.getUserId());
		boolean fOK = false; 
		if (userEntry.getRole().equals("user"))
		{
			c++;
			if (userScoreEntry.getTotalScore() != last_score)
				last_place = c;
			last_score = userScoreEntry.getTotalScore();
			fOK = true;
		}
%>


<tr>
	<td class="st_place"><%= fOK && last_score > 0 ? last_place : "*" %></td>
	<td class="st_team"><%= StringEscapeUtils.escapeHtml(userEntry.getName())  %></td>
<%
	int totalScore = 0;
	for (ContestProblemEntry problemEntry: problems)
	{
		ProblemUserScoreEntry score = monitor.getProblemUserScore(problemEntry.getId(), userEntry.getUserId());
		String txt = "-";
		if (score != null && score.getMaxScore() >= 0)
		{
			totalScore += score.getMaxScore();
			if (score.getAccepted())
				txt = "<b>" + score.getMaxScore() + "</b><div class=\"st_time\">(" + (score.getMaxScoreFirstTime() / 60000) + ")</div>";
			else
				txt = "" + score.getMaxScore() + " <div class=\"st_time\">(" + (score.getMaxScoreFirstTime() / 60000) + ")</div>";
		}
		String color = "white";
		if (score != null)
		{
			color = (score.getAccepted() ? "#ddffdd" : 
							(score.getPendingCount() > 0 ? "#ffffaa" :
								(score.getUniqueRejectedCount() > 0 ? "#ffaaaa" : "white")
							)
						);
		}
%>
	<td class="st_prob"  bgcolor="<%= color %>"><%= txt  %></td>
<%
	}
%>
	<td><%= userScoreEntry.getTotalScore() %></td>
	<td><%= userScoreEntry.getUniqueAcceptedCount()  %></td>
</tr>
<%
	}
%>

</table>


<%
	Long pageGenerationFinished = new Date().getTime();
%>

<!-- <%= "" + ((pageGenerationFinished - pageGenerationStarted)) + " ms" %>  -->


<%@include file="footer.jsp"%>
